package cloud.kiko.psn.user.rest;

import cloud.kiko.psn.pojo.common.biz.User;
import cloud.kiko.psn.pojo.common.R;
import cloud.kiko.psn.user.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * on 2023/2/12 23:32
 */
@RestController
@RequestMapping("user")
@Api(tags = "用户管理接口")
public class UserRest {
    @Resource
    private UserService userService;

    @ApiOperation(value = "获取用户信息")
    @GetMapping("/{id}")
    public R<?> queryById(@PathVariable(value = "id") long id) {
        User user = userService.getUserById(id);
        return R.ok(user);
    }

    @ApiOperation(value = "更新用户")
    @PutMapping
    public R<?> updateUser(@RequestBody User user) {
        userService.updateUser(user);
        return R.ok(user, "更新成功");
    }

    @ApiOperation(value = "删除缓存用户")
    @DeleteMapping("/{id}")
    public R<?> clearCachedUser(@PathVariable("id") long id) {
        boolean d = userService.clearCachedUser(id);
        return R.ok(d, "清除缓存成功");
    }
}
